package com.gsn.common;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.GsnImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.gsn.desktop.engine.ActorUtility;
import com.gsn.engine.gdx.GsnParticleActor;
import com.gsn.engine.myplay.GsnLayer;
import com.gsn.poker.asset.FontTexture;
import com.gsn.poker.asset.PokerSound;
import com.gsn.poker.asset.PortalTexture;

public class PortalNotEnoughMoneyLayer extends GsnLayer implements ClickListener {
	private static final String tag = "DialogLayer";
	float time = 0.5f;
	protected ParticleEffect clickEff;

	public PortalNotEnoughMoneyLayer(float width, float height) {
		super(width, height);

		Image bgDark = new Image(PortalTexture.inst().bgDarkDialog);
		PortalTexture.inst().scaleActor(bgDark);
		addActor(bgDark);
		bgDark.width = width;
		bgDark.height = height;

		Image bg = new Image(PortalTexture.inst().bgDialog);
		PortalTexture.inst().scaleActor(bg);
		addActor(bg);
		bg.x = (width - bg.width) / 2;
		bg.y = (height - bg.height) / 2;

		Label content = new Label("Bạn không đủ tiền để quy đổi, nạp thêm", new Label.LabelStyle(FontTexture.inst().fontMedium, new Color(1, 1, 1, 1)));
		addActor(content);
		content.x = bg.x + (bg.width - content.getTextBounds().width) / 2;
		content.y = bg.y + bg.height * 0.6f;

		Image iconG = new Image(PortalTexture.inst().iconGoldBig);
		PortalTexture.inst().scaleActor(iconG);
		addActor(iconG);
		iconG.x = content.x + content.getTextBounds().width + iconG.width * 0.2f;
		iconG.y = content.y;

		Label content1 = new Label("vào tài khoản đi nhé", new Label.LabelStyle(FontTexture.inst().fontMedium, new Color(1, 1, 1, 1)));
		addActor(content1);
		content1.x = bg.x + (bg.width - content1.getTextBounds().width) / 2;
		content1.y = content.y - content.getTextBounds().height * 1.5f;

		GsnImageButton agree = new GsnImageButton(PortalTexture.inst().agreeButton, PortalTexture.inst().agreeButtonPress);
		PortalTexture.inst().scaleActor(agree);
		addActor(agree);
		agree.x = bg.x + (bg.width - agree.getRealWidth()) / 2;
		agree.y = bg.y + bg.height * 0.1f;
		agree.setClickListener(this);

		clickEff = PortalTexture.inst().clickEff;
	}

	@Override
	public void click(Actor actor, float x, float y) {
		// TODO Auto-generated method stub
		hide();
		if (clickEff != null) {
			Vector2 v = ActorUtility.getCoordinate(actor, x, y, this.root);
			GsnParticleActor par = new GsnParticleActor(clickEff);
			par.setPostition(v.x, v.y);
			par.start();
			this.addActor(par);
		}
		PokerSound.playClick();
	}

	public InputProcessor oldInput;

	public void show() {
		oldInput = Gdx.input.getInputProcessor();
		visible = true;
		setInputListener();
	}

	public void hide() {
		Gdx.input.setInputProcessor(oldInput);
		oldInput = null;
		visible = false;
	}

}
